#!/bin/bash

# 		-----------basic-----------
alias ll='ls --color=auto -lht' #按修改时间逆序列出文件
alias la='ls --color=auto -lhta' #按修改时间逆序列出所有文
alias ls='ls --color=auto ' #按修改时间逆序列出所有文
## macro
alias current='date +%Y%d%m'


## locate
alias loc='f(){ sudo updatedb && locate $1; }; f'

## 目录管理
mcd() { mkdir -p "$1"; cd "$1";}
cds() { cd "$1"; ls -lht; }


### 备份
cps() { sudo cp -r "$1"  "$1.`date +%Y%m%dT%H%M`"; }
tars() { tar czvf "$1.`date +%Y%m%dT%H%M`".tar.gz "$1"; }

##  切换
alias ..='cd ..'
alias ...='cd ../..'
#alias tree="ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'"


## 改变权限
alias chadmin='f(){ sudo chown $(whoami) $1; }; f'
alias chadminr='f(){ sudo chown -R  $(whoami) $1; }; f'



## 解压
alias untar='tar xvf '
alias unjar='jar xvf '

## ----------network-----------

alias ipe='curl ipinfo.io/ip'
alias listen="f(){ lsof -i:$1; };f"
alias ipconfig="ping -c 1 `hostname` | awk '{if(NR==1) print \$3}'"


#-----System info---------
alias auto='systemctl list-unit-files --type=service | grep enabled | more'

## 已经挂载的盘
alias cmount="mount | column -t"

alias ps?="ps aux | grep"
alias port?='sudo netstat -tulanp | grep $1'

## 查看硬盘使用量
alias rootu="df -h |grep -w "/" |awk '{print \$5}'"
alias datau="df -h |grep -w "/cetc/data1" |awk '{print \$5}'"


# 内存信息
alias mem='free -m -l -t -h'


## 负载
alias uptime=" cat /proc/loadavg|awk '{print \$1,\$2,\$3}' "


alias proc='cat /proc/cpuinfo | grep "processor"| wc -l'
alias phy='cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l'


# 大小
alias size='f(){ du -sh  $1* | sort -hr; }; f'



# 查看日志
alias log='f(){ tail -f -n 1000 $1; };f'


# ----------trash------
alias trm='sudo trash-put'


alias play='f() { ansible-playbook $1; };f'
alias playtag='f() { ansible-playbook --tags=$1 $2; };f'
alias sc='sudo supervisorctl -c /etc/supervisord.conf'
alias sysr="sudo systemctl daemon-reload"

alias sys='f() { sudo systemctl $1 $2; };f'


## 其他

md5check() { md5sum "$1" | grep "$2"; }
alias now='date "+%Y-%m-%d %H:%M:%S"'
alias his=history
alias wget='wget -c '


## 校验checksum
alias sha='shasum -a 256 '
alias getpass="openssl rand -base64 20"
alias ping='ping -c 5'


##  iptables
alias portopen='f(){ /sbin/iptables -I INPUT -p tcp --dport $1 -j ACCEPT; }; f'
alias portclose='f(){ /sbin/iptables -I INPUT -p tcp --dport $1 -j DROP; }; f'

## python
alias www='f(){ python -m SimpleHTTPServer $1; }; f'
alias c='clear'

## env
alias act="source ~/.bashrc"
alias dact="deactivate"